#include "ImageManager.h"


ImageManager* ImageManager::m_instance = NULL;
ImageManager* ImageManager::getInstance()
{
    if(!m_instance)
    {
        m_instance = new ImageManager();
    }
    return m_instance;
}

/// constructor
ImageManager::ImageManager()
{
}

/// destructor
ImageManager::~ImageManager()
{

}

void ImageManager::cleanup()
{
    m_images.clear();
    if(m_instance)
    {
        delete m_instance;
    }
}


/// gets an image from the list if it exists or creates one if it dosent
sf::Image& ImageManager::getImage(std::string image_name)
{
    m_iterator = m_images.find(image_name);
    if(m_iterator == m_images.end())
    {
        return m_addImage(image_name);
    }
    return m_iterator->second;
}


/// adds an image to the list
sf::Image& ImageManager::m_addImage(std::string image_name)
{
    sf::Image temp;
    temp.LoadFromFile(image_name);
    temp.CreateMaskFromColor(sf::Color(255,0,255));
    m_images.insert(std::make_pair<std::string, sf::Image>(image_name, temp)); // i dont think i need the template brackets but its fine

    m_iterator = m_images.find(image_name);
    return m_iterator->second;
}

